package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.bean.MallBean;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by administrator on 2018/11/21.
 */
public class HomeSortAdapter extends BaseQuickAdapter<HomeMerBean.ProductListBean, BaseViewHolder> {


    public HomeSortAdapter(@Nullable List<HomeMerBean.ProductListBean> data) {
        super(R.layout.item_sort_food, data);
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
//        addData(new MallBean.KtProductListBean());
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeMerBean.ProductListBean item) {
        helper.setText(R.id.tv_goods_name, item.getTradename());
        helper.setText(R.id.tv_benifit_kind, item.getDescribed());
        if (!TextUtils.isEmpty(item.getWeight())) {
            helper.setText(R.id.tv_unit_price, item.getWeight() + "g");
        } else {
            helper.setText(R.id.tv_unit_price, "");
        }
        helper.setText(R.id.tv_goods_price, getPrice(item));

        ImageView ivGoodPic = helper.getView(R.id.iv_goods_banner);
        String imgPath = "";
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] imgarr = item.getImg_zt().split(",");
            imgPath = imgarr[0];
        }
        GlideUtils.loadRoundImg(mContext, ivGoodPic, imgPath, R.mipmap.default_foods_icon, 4);
        if (TextUtils.isEmpty(item.getShopbv()) || Double.parseDouble(item.getShopbv()) == 0.0) {
            helper.setGone(R.id.tv_shop_bv, false);
        } else {
            helper.setVisible(R.id.tv_shop_bv, true);
            helper.setText(R.id.tv_shop_bv, item.getShopbv() + "BV");
        }
        helper.addOnClickListener(R.id.ll_item_view);
        helper.addOnClickListener(R.id.iv_sort_car);
    }


    @NotNull
    private String getPrice(HomeMerBean.ProductListBean bean) {
        String price = "";
        if (!TextUtils.isEmpty(bean.getPrice()) && Double.parseDouble(bean.getPrice()) != 0.00) {
            price += "¥";
            price += bean.getPrice();
        }
        if (!TextUtils.isEmpty(bean.getMarket_price()) && Double.parseDouble(bean.getMarket_price()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += bean.getMarket_price();
                price += "积分";
            } else {
                price += bean.getMarket_price();
                price += "积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "¥0.00";
        }
        return price;
    }

}
